﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.Converter/IsEvenConverter
* 类       名: IsEvenConverter
* 功      能:  是否是偶数的判断转换器
* 时      间:  2023/7/20 11:05:30
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace SiliconSelect.Converter
{
    public class IsCheckedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string temp)
            {
                if (temp.Contains("true", StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 如果选中,将绑定的变量的值赋值为True_False
        /// 如果没有选中,将绑定的变量的值赋值为False_False
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool isChecked = (bool)value;
            if (isChecked)
            {
                return "TRUE";
            }
            else
            {
                return "FALSE";
            }
        }
    }
}
